package com.rcl.recyclerviewdemo.java;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/*
 * class title:
 * Author by RenChunLin, Email 18957806320@163.com, Date on 2020/11/3.
 * PS: Not easy to write code, please indicate.
 */
public class ListTest {

    public static void main(String[] args) {
        List<String> list = Arrays.asList("张三", "李四", "王二", "张三", "小东", "明明", "张三", "小李","娃娃","小东");
        List<String> integers = returnList(list);
        for (String integer : integers) {
            System.out.println(integer);
        }
    }

    public static List<String> returnList(List<String> list) {
        Map<String, List<String>> map = new HashMap<>();
        for (String num : list) {
            if (map.containsKey(num)) {
                map.get(num).add(num);
            } else {
                List<String> sNewList = new ArrayList<>();
                sNewList.add(num);
                map.put(num, sNewList);
            }
        }
        //System.out.println(map);
        List<String> sAa = new ArrayList<>();
        Set<Map.Entry<String, List<String>>> entries = map.entrySet();
        for (Map.Entry<String, List<String>> entry : entries) {
            sAa.addAll(entry.getValue());
        }
        return sAa;
    }
}
